//直接获取SalaryDistribution(薪酬发放表)里的InstName作为三级机构名，二级机构名为三级机构的pid，一级机构名为二级机构的pid；总人数为PersonNum。
//

var salaryDistributionData;// 定义一个全局变量
//初始化页面数据

function initial(){
    /**
    JSON.stringify()是将JavaScript对象转换为json字符串
    JSON.parse(jsonstr)是将json字符串转换为javascript对象
    */
    $.ajax({
        url:"http://localhost/PersonManSystem/salary/distribution/query/no/book.action",//待补充
        type:"get",
        dataType:'json',
        contentType:'application/json;charset=utf-8',
        success:function(data){

            salaryDistributionData = data;
           
            $.each(data['data'], function(i, item){
                var tbody = $('<tr style="FONT-WEIGHT: bold; FONT-STYLE: normal; BACKGROUND-COLOR: #eeeeee; TEXT-DECORATION: none"></tr>');

                 tbody.append("<td>"+item.firstinstname+"</td>");
                 tbody.append("<td>"+item.secondinstname+"</td>");
                 tbody.append("<td>"+item.thirdinstname+"</td>");
                 tbody.append("<td>"+item.personnum+"</td>");
                 tbody.append("<td>"+item.basicsalarysum+"</td>");


                 tbody.append("<td><input type='button' id='"+item.thirdinstname+"' value='登记' onclick='getid(this)'></td>");

                 $("#grid").append(tbody);
            });
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            alert("Error");
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
        }
    });

}


function getid(obj){
    $(salaryDistributionData['data']).each(function(){
        if (obj.id == this.thirdinstname){
            sessionStorage.setItem("XCFFsalarydistributionid", this.salarydistributionid);
            sessionStorage.setItem("XCFFthirdinstname",this.thirdinstname);
            sessionStorage.setItem("XCFFsecondinstname", this.secondinstname);
            sessionStorage.setItem("XCFFfirstinstname", this.firstinstname);
            sessionStorage.setItem("XCFFbasicsalarysum", this.basicsalarysum);
            sessionStorage.setItem("XCFFpersonnum", this.personnum);


        }
    });
    window.location = 'XCFFDJMX.html';
}
